home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 1 (Walnut Creek)
/
Aminet - June 1993 [Walnut Creek].iso
/
usenet
/
sources
/
volume91
/
utilitys
/
dog_1_11
/
part01
/
dog.c
next >
Wrap
C/C++ Source or Header
|
1991-07-04
|
3KB
|
149 lines
/*
DOG
Create a rename script
to unmangle the ms-dog
filenameing convention
Version 1.11
--
If you have net access on a unix box, but have to transport software
through an ms-dos machine to get is to your amiga, no doubt you hate
the fact that ms-dog cannot support full amiga filenames.
This is no longer a problem now that you have DOG.
Compile DOG on your local unix box, and then run it with the command
line:
DOG [filenames]
DOG will create a file called !RENAME in the current directory and will
rename all the specified files to have names that are unique to a dos
machine.
Now transport the files to your amiga, via the dog-box and type the line
on your amiga:
Execute !RENAME
Now all your files are called what they were originally!
If you want to un-DOG the files on a unix box instead, then type:
/bin/csh !RENAME
And the files will be returned.
--
(c) 1991 Phil Kernick / Wizard Software
This program is freely distributable as long as
the above copyright message is left intact.
Please send any bugs or comments to:
phil@adam.adelaide.edu.au
Phil Kernick
304 South Terrace
Adelaide
SA 5000
AUSTRALIA
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#define min(a,b) ((a) < (b) ? (a) : (b))
#define max(a,b) ((a) > (b) ? (a) : (b))
#define DUMPFILE "!RENAME"
char doschar[] = "\
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX!XX$%&'()XXX-.X0123456789XXXXXX\
@ABCDEFGHIJKLMNOPQRSTUVWXYZXXX^_`ABCDEFGHIJKLMNOPQRSTUVWXYZ{X}XX\
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
typedef char (*fnp)[13];
main(argc, argv)
int argc;
char **argv;
{
int fname, dot, node, rpt;
char buffer[256], ext[8], *cc, *dd;
fnp dosfile;
FILE *fp;
dosfile = (fnp) malloc(argc * sizeof(*dosfile));
strcpy(dosfile[0], DUMPFILE);
for (fname = 1; fname < argc; fname++)
{
for (dot = 0, cc = argv[fname], dd = buffer; *cc; cc++, dd++)
*dd = ((*cc == '.') ? (dot++ ? 'X' : '.') : doschar[*cc]);
*dd = '\0';
for (dot = 0, dd = buffer, cc = dosfile[fname];
(dot < 8) && *dd && (*dd != '.'); dot++)
*cc++ = *dd++;
node = dd - buffer;
if (*dd != '.')
for (; *dd && (*dd != '.'); dd++) ;
for (dot = 0; (dot < 4) && *dd; dot++)
*cc++ = *dd++;
*cc = '\0';
for (dot = 0; dot < fname; dot++)
if (strcmp(dosfile[dot], dosfile[fname]) == 0)
{
if (node != 8)
rpt = 1;
else
{
for (cc = &dosfile[fname][node - 1]; isdigit(*cc); --cc) ;
rpt = atoi(++cc) + 1;
}
sprintf(buffer, "%0d", rpt);
strcpy(ext, &dosfile[fname][node]);
rpt = max(8 - strlen(buffer) - node, 0);
for (dd = buffer + strlen(buffer), cc = dosfile[fname] + 8;
dd >= buffer;)
*cc-- = *dd--;
for (; rpt > 0; rpt--)
*cc-- = '0';
strcat(dosfile[fname], ext);
dot = -1;
}
}
for (node = 0, fname = 1; fname < argc; fname++)
if (strcmp(argv[fname], DUMPFILE) != 0)
{
if (strcmp(dosfile[fname], argv[fname]) != 0)
{
if (!node)
{
fp = fopen(DUMPFILE, "w");
fprintf(fp, "; alias rename mv\n");
node = !node;
}
fprintf(fp, "rename %s \"%s\"\n", dosfile[fname], argv[fname]);
rename(argv[fname], dosfile[fname]);
}
}
if (node)
fclose(fp);
free((char *) dosfile);
}